﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EzDesk.DevHelper.DbMgr.Presenters;

namespace EzDesk.DevHelper.DbMgr.Views
{
    public partial class FeedPanel : UserControl, IFeedMainView
    {
        private FeedMainPresenter _presenter;

        public FeedPanel()
        {
            InitializeComponent();

            _presenter = new FeedMainPresenter(this);
        }

        void setStatusText(string str)
        {
            lblStatusText.Text = string.Format("[{0}] - {1}",
                DateTime.Now.ToString(),
                str
                );
        }

        private string _selectFeedName = null;
        public string FeedName
        {
            get
            {
                return _selectFeedName;
            }
        }

        public void DisplayFeedTemplatesList(dynamic strs)
        {
            FeedList.Items.Clear();
            foreach (var str in strs)
            {
                FeedList.Items.Add(str.TemplateName);
            }
        }



        public void ClearTestList()
        {
            FeedList.Items.Clear();
        }



        private void btnAdd_Click(object sender, EventArgs e)
        {
            var templateName = _presenter.AddNewFeed();

            var feedForm = new FeedForm(templateName, _presenter);

            feedForm.Show();
        }

        private void btnDelet_Click(object sender, EventArgs e)
        {
            _selectFeedName = FeedList.SelectedItem as String;

            _presenter.DeleteFeed(_selectFeedName);
        }

        private void FeedList_DoubleClick(object sender, EventArgs e)
        {
            if (FeedList.SelectedItems.Count == 1)
            {
                _selectFeedName = FeedList.SelectedItem as String;
                var feedForm = new FeedForm(_selectFeedName,_presenter);

                feedForm.Show();
            }
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            _presenter.RefreshFeedList();
            setStatusText("获取FeedTemplate List完毕");
        }



        private void button1_Click(object sender, EventArgs e)
        {
            _presenter.RefreshFeedList();
            setStatusText("获取FeedTemplate List完毕");
        }
        

        public void WriteLine(string p)
        {
            (this.ParentForm as IMainFormView).WriteLine(p);
        }
    }
}
